package xpn.platform.modules.workflow.definition.action;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.config.Projection;
import xpn.platform.common.repository.XpnRepository;

import xpn.platform.modules.workflow.definition.state.State;
import xpn.platform.modules.workflow.other.commentcolumn.CommentColumn;

import java.util.List;

/**
 * 任务：表示一个流程状态下需要执行者执行的任务
 *
 * @author bobatkm
 * @version 2017年8月31日 上午9:26:35
 */
@RepositoryRestResource(path = "workflow_definition_actions", excerptProjection = ActionDefaultProjection.class)
@SuppressWarnings("unchecked")
public interface ActionDAO extends XpnRepository<Action, Long> {
	/*
	 * 保存权限控制
	 */
	@RequiresPermissions("workflow.admin")
	@Override
	Action save(Action entity);

	/*
	 * 删除权限控制
	 */
	@RequiresPermissions("workflow.admin")
	@Override
	void delete(Action entity);

	/**
	 * 根据状态查询其中所有操作
	 *
	 * @return 操作列表
	 */
	Page<Action> findByState(State state, Pageable pageable);

	/**
	 * 根据状态查询其中所有操作
	 *
	 * @param state
	 *            状态
	 * @return 操作列表
	 */
	List<Action> findByStateOrderBySortNo(State state);
}

/**
 * 缺省投影
 *
 * @author yjx
 */
@Projection(name = "default", types = { Action.class })
interface ActionDefaultProjection {

	Long getId();

	State getState();

	String getName();

	String getMessage();

	ActionTypeEnum getActionType();

	String getAuthorizationRule();

	State getSendeeState();

	WaitModeEnum getWaitMode();

	DelegateModeEnum getDelegateMode();

	Boolean getKeepAsExecutor();

	String getDescription();

	Integer getOuLevel();

	Integer getOuType();

	String getRoleCondition();

	String getSpecificReceiverUrl();

	Boolean getCanTakeBack();

	SendModeEnum getSendMode();

	CommentColumn getCommentColumn();

	UITypeEnum getUiType();

	Boolean getCompleteTodo();

	Boolean getCheckComment();

	String getDefaultComment();

	Action getParentProcessAction();

	Boolean getCompleteReceiverOldToDos();

	String getNo();

	String getSortNo();
	@Value("#{target.getSendeeState()==null?null:target.getSendeeState().getId()}")
    Long getStateId();

    @Value("#{target.getSendeeState()!=null?target.getSendeeState().getName():null}")
    String getStateName();

}
/**
 * 缺省投影
 *
 * @author yjx
 */
@Projection(name = "list", types = { Action.class })
interface ActionListProjection {

	Long getId();

	State getState();

	String getName();

	String getMessage();

	ActionTypeEnum getActionType();

	String getAuthorizationRule();

	State getSendeeState();

	WaitModeEnum getWaitMode();

	DelegateModeEnum getDelegateMode();

	Boolean getKeepAsExecutor();

	String getDescription();

	Integer getOuLevel();

	Integer getOuType();

	String getRoleCondition();

	String getSpecificReceiverUrl();

	Boolean getCanTakeBack();

	SendModeEnum getSendMode();

	CommentColumn getCommentColumn();

	UITypeEnum getUiType();

	Boolean getCompleteTodo();

	Boolean getCheckComment();

	String getDefaultComment();

	Action getParentProcessAction();

	Boolean getCompleteReceiverOldToDos();

	String getNo();

	String getSortNo();
	@Value("#{target.getSendeeState()==null?null:target.getSendeeState().getId()}")
    Long getStateId();

    @Value("#{target.getSendeeState()!=null?target.getSendeeState().getName():null}")
    String getStateName();

}